#include <cstdio>
#include <algorithm>
#define mod 100000007
using namespace std;

int n, m, p, a[ 360001 ], b[ 360001 ], next[ 360001 ];
int prime[ 601 ], primec;
bool visit[ 601 ];

void getprime( )
{
    int i, j;
    for ( i = 2; i <= 600; i++ )
        if ( !visit[ i ] )
        {
            prime[ primec++ ] = i;
            for ( j = i * 2; j <= 600; j += i )
                visit[ j ] = 1;
        }
}

void getnext( int *a, int *next )
{
    int i, j = -1;
    next[ 0 ] = -1;
    for ( i = 1; i < m; i++ )
    {
        while ( j >= 0 && a[ j + 1 ] != a[ i ] ) j = next[ j ];
        if ( a[ j + 1 ] == a[ i ] ) j++;
        next[ i ] = j;
    }
}

void init( )
{
    int i;
    for ( i = 0; i < m; i++ )
        scanf("%d", &a[ i ]);
    sort( a, a + m );
    for ( i = 0; i < m - 1; i++ )
        b[ i ] = a[ i + 1 ] - a[ i ];
    b[ m - 1 ] = a[ 0 ] + 360000 - a[ m - 1 ];
    getnext( b, next );
    if ( m % ( m - next[ m - 1 ] - 1 ) == 0 )
        p = m / ( m - next[ m - 1 ] - 1 );
    else
        p = m;
}

long long euler( long long n )
{
    long long ret = n;
    int i;
    for ( i = 0; i < primec && prime[ i ] * prime[ i ] <= n; i++ )
        if ( n % prime[ i ] == 0 )
        {
            ret = ret * ( prime[ i ] - 1 ) / prime[ i ];
            while ( n % prime[ i ] == 0 )
                n /= prime[ i ];
        }
    if ( n > 1 )
        ret = ret * ( n - 1 ) / n;
    return ret;
}

long long pow( int a, int n )
{
    int p = 1;
    long long ret = 1;
    while ( p <= n ) p <<= 1;
    p >>= 1;
    while ( p )
    {
        ret = ret * ret % mod;
        if ( p & n )
            ret = ret * a % mod;
        p >>= 1;
    }
    return ret;
}

long long extgcd( long long a, long long b, long long &x, long long &y )
{
    if ( b == 0 ) { x = 1; y = 0; return a; }
    long long d = extgcd( b, a % b, x, y );
    long long t = x; x = y; y = t - a / b * y;
    return d;
}

void work( )
{
    int i;
    long long x, y;
    long long ans = 0, d = pow( n, m / p );
    for ( i = 1; i * i < p; i++ )
        if ( p % i == 0 )
        {
            ans = ( ans + euler( p / i ) * pow( d, i ) ) % mod;
            ans = ( ans + euler( i ) * pow( d, p / i ) ) % mod;
        }
    if ( i * i == p )
        ans = ( ans + euler( i ) * pow( d, i ) ) % mod;
    extgcd( p, mod, x, y );
    x = ( x + mod ) % mod;
    printf("%I64d\n", ans * x % mod);
}

int main( )
{
    getprime( );
    while ( scanf("%d%d", &n, &m) )
    {
        if ( n == -1 && m == -1 ) break;
        init( );
        work( );
    }
    return 0;
}
